/*
 * @(#)ActionListenerAdapter.java 0.5 08/12/04
 *
 * Copyright 2008 100town.com. All rights reserved.
 * Use is subject to license terms.
 */
package ImplSample.action;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import org.collada.model.Action;
import org.collada.model.ActionType;
import org.collada.anim.ModelControl;
import org.collada.anim.RunningType;
import org.collada.util.action.ModelEvent;

/**
 * 
 * 
 *
 */
public class ActionListenerAdapter implements ActionListener{
	public void actionPerformed(ActionEvent e){
		if(e instanceof ModelEvent){
			ModelEvent modelEvent = ((ModelEvent)e);
			Action modelAction = modelEvent.getModelAction();
			System.out.println("with action ID: " + e.getID() + "  actionID: " + modelAction.getActionID()
					+ ", actionType " + modelEvent.getModelAction().getActionType());
			ActionType actionType = modelAction.getActionType();
			ModelControl modelControl = modelAction.getModelControl();
			switch(actionType){
			case START:
				modelControl.setRunningType(RunningType.REPEAT);
				modelControl.setActive(true);
				System.out.println("I am walking!");
				break;
			case STOP:
				modelControl.setActive(false);
				System.out.println("I am resting!");
				break;
			case RESET:
				//The difference between stop and reset is: by stop the model is frozen at key time; by reset the model is frozen at start key time;
				modelControl.setActive(false);
				System.out.println("Reset!");
				break;
			case RUN_ONCE:
				modelControl.setRunningType(RunningType.ONCE);
				modelControl.setActive(true);
				break;
			case TOGGLE:
				if(modelControl.isActive()){
					modelControl.setActive(false);
					System.out.println("I am turn to resting!");
				}else{
					modelControl.setActive(true);
					modelControl.setRunningType(RunningType.REPEAT);
					System.out.println("I am turn to walking!");
				}
				break;
			case RUN_SEVERAL_TIMES:
				modelControl.setRunningType(RunningType.LIMITED_REPEAT);
				modelControl.setRepeatTimes(modelAction.getRunningTimes());
				modelControl.setActive(true);
				break;
			}
		}
	}
}